<?php namespace Admin\Controller;

use Admin\Model\Brand;

class BrandController extends AuthController{
	protected $db;
	//构造函数
	public function __init()
	{
		$this->db = new Brand;
	}

    //动作
	public function index(){
		$data = $this->db->getAll();
		View::with('data',$data);
		View::make();
	}

	public function add(){
		if(IS_POST)
		{
			if($this->db->store())
			{
				View::success('添加成功',U('index'));
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			View::make();
		}
	}

	public function edit(){
		if(IS_POST)
		{
			if($this->db->edit())
			{
				View::success('操作成功',U('index'));
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			$field = $this->db->one($_GET['id']);
			View::with('field',$field);
			View::make();
		}
	}
}
